package tw.twandroidproj.app.network;

import java.util.Iterator;
import java.util.Map;

/**
 * Created by freeze on 2015/4/25.
 * 一些网络的参数
 */
public class NetParams {
    public static final String HOST = "http://tjz.frezc.com";

    public static final String AUTH_URL = HOST + "/auth";
    public static final String AUTH_PHONE = HOST + "/authPhone";
    public static final String REFRESH = HOST + "/refresh";
    public static final String REGISTER = HOST + "/register";
    public static final String REGISTER_BY_PHONE = HOST + "/registerByPhone";
    public static final String RESET_PASSWORD = HOST + "/resetPassword";
    public static final String BIND_PHONE = HOST + "/bindPhone";
    public static final String BIND_EMAIL = HOST + "/bindEmail";
    public static final String SEND_VERIFY_EMAIL = HOST + "/sendVerifyEmail";
    public static final String VERIFY_EMAIL = HOST + "/verifyEmail";
    public static final String USER_URL = HOST + "/users";
    public static final String USER_UPDATE = USER_URL;
    public static final String AVATAR_URL = HOST + "/avatar";
    public static final String RESUME_URL = HOST + "/users";
    public static final String RESUME_PHOTO= RESUME_URL + "/photo";
//    public static final String RESUME_DELETE_URL = RESUME_URL + "/delete";
//    public static final String RESUME_ADD_URL = RESUME_URL + "/add";
//    public static final String RESUME_UPDATE_URL = RESUME_URL + "/update";
    public static final String RESUME_PUBLIC_URL = RESUME_URL + "/public";
    public static final String JOB_URL = HOST + "/jobs";
    public static final String JOB_QUERY_URL = JOB_URL;
    public static final String JOB_APPLY = HOST + "/job/apply";
    public static final String JOB_EVALUATE = JOB_URL + "/evaluate";
    public static final String COMPANY_URL = HOST + "/companies";
    public static final String COMPANY_QUERY_URL = COMPANY_URL;
    public static final String GET_SMS_CODE = HOST + "/getSmsCode";
    public static final String GET_ALL_JOB= HOST + "/getAllJob";
    public static final String SUER_APPLY_JOB=HOST+"/sureAppJob";
    public static final String RELEASE_JOB=HOST+"/releaseJob";
    public static final String SMS_NEW=HOST+"/umsg";
    /***
     * 用来构造query参数的一个方法
     * @param baseUrl 要访问的url, 如 NetParams.JOB_QUERY_URL
     * @param query query形式的参数, 如 Map<String, String> map = new HashMap<String, String>(); map.put("q", "备胎");
     * @return 得到的url, 如 http://api.frezc.com/job/query?q=备胎
     */
    public static String structureQueryUrl(String baseUrl, Map<String, String> query){
        if (query == null || query.isEmpty()){
            return baseUrl;
        }

        StringBuilder sb = new StringBuilder(baseUrl);
        sb.append("?");

        boolean first = true;

        for (Map.Entry<String, String> entry : query.entrySet()) {
            if (first){
                first = false;
            } else {
                sb.append("&");
            }
            sb.append(entry.getKey());
            sb.append("=");
            sb.append(entry.getValue());
        }

        return sb.toString();
    }

    /***
     * 用来构造path参数的方法
     * @param baseUrl url, 如 NetParams.USER_URL
     * @param path path参数, 如 "1"
     * @return 得到的url, 如 http://api.frezc.com/user/1
     */
    public static String structurePathUrl(String baseUrl, String path) {
        if (path != null){
            baseUrl += "/"+ path;
        }
        return baseUrl;
    }

}
